/****************************************************
 *
 * 项目名称：  com.heroh.db
 * All rights Reserved, Designed By 投资交易团队
 * @Copyright:2016-2021
 *
 ********************************************************/

package com.heroh.db;

import org.springframework.util.StringUtils;

/**
 * 包名称： com.heroh.db
 * 类名称：DbConfig
 * 类描述：数据库配置
 * 创建人：@author shengxiong.jian
 * 创建时间：2021/3/8/11:07
 */
public class DbConfig {

    /**
     * 驱动
     */
    private String driver;
    /**
     * url
     */
    private String url;
    /**
     * 用户名
     */
    private String user;
    /**
     * 密码
     */
    private String password;

    public DbConfig(Builder builder) {
        this.driver = builder.driver;
        this.url = builder.url;
        this.user = builder.user;
        this.password = builder.password;
    }

    public String getDriver() {
        return driver;
    }

    public String getUrl() {
        return url;
    }

    public String getUser() {
        return user;
    }

    public String getPassword() {
        return password;
    }

    public static class Builder{
        private String driver;
        private String url;
        private String user;
        private String password;

        public DbConfig build(){
            if(StringUtils.isEmpty(driver)){
                throw new RuntimeException("数据库驱动不能为空");
            }
            if(StringUtils.isEmpty(url)){
                throw new RuntimeException("数据库url不能为空");
            }
            if(StringUtils.isEmpty(user)){
                throw new RuntimeException("数据库用户不能为空");
            }
            if(StringUtils.isEmpty(password)){
                throw new RuntimeException("数据库密码不能为空");
            }
            return new DbConfig(this);
        }

        public Builder setDriver(String driver) {
            this.driver = driver;
            return this;
        }

        public Builder setUrl(String url) {
            this.url = url;
            return this;
        }

        public Builder setUser(String user) {
            this.user = user;
            return this;
        }

        public Builder setPassword(String password) {
            this.password = password;
            return this;
        }
    }
}
